package com.yykj.pay.server.controller;

import com.yykj.pay.center.client.dto.ClientPayConfigDTO;
import com.yykj.pay.center.client.form.PayCreateForm;
import com.yykj.pay.server.service.ClientPayConfigService;
import com.yykj.pay.server.service.PaymentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.Map;


@RestController
@RequestMapping("/proto/pay")
@Api(tags = "支付")
@Slf4j
public class ProtoController {

    @Autowired
    PaymentService paymentService;

    @Autowired
    ClientPayConfigService clientPayConfigService;

    @ApiIgnore
    @PostMapping("/create")
    @ApiOperation(value = "微信小程序下单,返回支微信付信息")
    public Map<String, String> create(@RequestBody @Valid PayCreateForm payCreateForm) {
        return paymentService.create(payCreateForm);
    }

    @GetMapping("/config/get")
    @ApiOperation(value = "获取医院支付环境配置")
    public ClientPayConfigDTO get(@RequestParam("hospitalId") String hospitalId) {
        return clientPayConfigService.get(hospitalId);
    }

    @GetMapping("/refund")
    @ApiOperation(value = "微信退款")
    public boolean refund(@RequestParam("order") String order, @RequestParam("hospitalId") int hospitalId) {
        return paymentService.refund(order, hospitalId);
    }

    @GetMapping("/tmp/refundForUsercenter")
    @ApiOperation(value = "微信退款 临时给usercenter用")
    public boolean refundForUsercenter(@RequestParam("order") String order,@RequestParam("fee") int fee,@RequestParam("hospitalId") int hospitalId) {
        return paymentService.refundForUsercenter(order, fee, hospitalId);
    }
}